home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / BPAS9.ARJ / ELECTRIC.PAS < prev    next >
Pascal/Delphi Source File  |  1991-09-07  |  2KB  |  80 lines

  1. PROGRAM Electricity;                     { See Tom Swan pp. 69-71 }
  2. CONST
  3.    MaxRow = 12;      { Number rows in table }
  4.    MaxCol = 8;       { Number columns in table }
  5. VAR
  6.    StartHours,
  7.    HourlyIncrement,
  8.    StartWatts,
  9.    WattsIncrement,
  10.    CostPerKwh     : Real;
  11.  
  12. PROCEDURE Initialize;
  13. BEGIN
  14.    WriteLn( '        Cost of electricity' );
  15.    WriteLn;
  16.    Write( '   Starting number of hours .......? ' ); ReadLn( StartHours );
  17.    Write( '   Hourly increment ...............? ' ); ReadLn( HourlyIncrement );
  18.    Write( '   Starting number of Watts .......? ' ); ReadLn( StartWatts );
  19.    Write( '   Watts increment ................? ' ); ReadLn( WattsIncrement );
  20.    Write( '   Cost per kilowatt hour (KWH) ...? ' ); ReadLn( CostPerKwh)
  21. END;  {Initialize}
  22.  
  23. FUNCTION Cost( Time, Power, Rate : Real ) : Real;
  24. { Return cost of running at "Power" watts for "Time" hours }
  25. BEGIN
  26.    Cost := Rate * ( Power * 0.001 * Time )
  27. END;  {Cost}
  28.  
  29. PROCEDURE PrintTable;
  30. VAR
  31.    Row, Col      : Integer;
  32.    Hours, Watts  : Real;
  33. BEGIN
  34.    WriteLn;
  35.    Write( 'Hrs/Watts' );
  36.    Watts  := StartWatts;
  37.    For Col := 1 to MaxCol DO
  38.    BEGIN
  39.       Write( Watts:8:0 );
  40.       Watts := Watts + WattsIncrement
  41.    END;  {for }
  42.    WriteLn;
  43.  
  44.    Hours := StartHours;
  45.    For row := 1 to MaxRow DO
  46.    BEGIN
  47.       WriteLn;
  48.       Write( Hours:6:1, '-' );
  49.       Watts := StartWatts;
  50.       FOR Col := 1 to MaxCol DO
  51.       BEGIN
  52.         Write( Cost( Hours, Watts, CostPerKwh ):8:2 );
  53.         Watts := Watts + WattsIncrement
  54.       END;  {for}
  55.       Hours := Hours + HourlyIncrement
  56.    END; { for }
  57.    WriteLn;
  58.    WriteLn;
  59.    WriteLn( 'Cost of Electricity @ ', CostPerKwh:0:4, ' per KWH' )
  60. END;  {PrintTable}
  61.  
  62. FUNCTION Finished : Boolean;
  63. VAR
  64.    answer  : Char;
  65. BEGIN
  66.    WriteLn;
  67.    Write( 'Another table (y/n) ? ' );
  68.    ReadLn( answer );
  69.    Finished := Upcase( answer ) <> 'Y'
  70. END;  {Finished }
  71.  
  72. BEGIN
  73.    REPEAT
  74.       Initialize;
  75.       PrintTable
  76.    UNTIL Finished
  77. END.
  78.  
  79.  
  80.